package com.css.project.process.definition.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.css.framework.aspectj.lang.annotation.Log;
import com.css.framework.aspectj.lang.enums.BusinessType;
import com.css.project.process.definition.domain.ProcessDefinition;
import com.css.project.process.definition.service.IProcessDefinitionService;
import com.css.framework.web.controller.BaseController;
import com.css.framework.web.domain.AjaxResult;
import com.css.common.utils.poi.ExcelUtil;
import com.css.framework.web.page.TableDataInfo;

/**
 * 流程定义Controller
 * 
 * @author dumk
 * @date 2020-04-22
 */
@RestController
@RequestMapping("/process/definition")
public class ProcessDefinitionController extends BaseController
{
    @Autowired
    private IProcessDefinitionService processDefinitionService;

    /**
     * 查询流程定义列表
     */
    @PreAuthorize("@ss.hasPermi('process:definition:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProcessDefinition processDefinition)
    {
        startPage();
        List<ProcessDefinition> list = processDefinitionService.selectProcessDefinitionList(processDefinition);
        return getDataTable(list);
    }

    /**
     * 导出流程定义列表
     */
    @PreAuthorize("@ss.hasPermi('process:definition:export')")
    @Log(title = "流程定义", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProcessDefinition processDefinition)
    {
        List<ProcessDefinition> list = processDefinitionService.selectProcessDefinitionList(processDefinition);
        ExcelUtil<ProcessDefinition> util = new ExcelUtil<ProcessDefinition>(ProcessDefinition.class);
        return util.exportExcel(list, "definition");
    }

    /**
     * 删除流程定义
     */
    @PreAuthorize("@ss.hasPermi('process:definition:remove')")
    @Log(title = "流程定义", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(processDefinitionService.deleteProcessDefinitionByIds(ids));
    }
}
